import { departmentTree } from "@/api/department"
function departmentTree1() {
  return new Promise(async (resolve, reject) => {
    let options1 = null
    await departmentTree().then((res) => {
      const options = JSON.parse(
        JSON.stringify(res.data).replace(/childrenDept/g, "children")
      );
      options1 = JSON.parse(
        JSON.stringify(options).replace(/deptName/g, "label")
      );
      handleData(options1);
    })

    resolve(options1)
  })

}

function handleData(data) {
  if (data) {
    data.forEach((element) => {
      element["value"] = element.id;
      if (element.children?.length < 1) {
        element.children = undefined;
      } else {
        handleData(element.children);
      }
    });
  }
  return data;
}
export default {
  departmentTree1
}

